package ch.cm.android.teamlearn.framents;

import java.sql.SQLException;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Toast;
import ch.cm.android.teamlearn.R;
import ch.cm.android.teamlearn.model.Question;
import ch.cm.android.teamlearn.orm.DataBaseHelper;

import com.j256.ormlite.dao.Dao;

public class QuestionList extends ListFragment {

    private static final String TAG = QuestionList.class.getName();
    private ArrayAdapter<Question> adapter;
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_question_list, container, false);
        return rootView;
    }

    @Override
    public void onResume() {
        super.onResume();
        List<Question> questions = null;
        try {
            Dao<Question, Integer> dao = new DataBaseHelper(getActivity()).getDao();
            questions = dao.queryForAll();
        } catch (SQLException e) {
            Log.e(TAG, e.getMessage());
        }

        adapter = new ArrayAdapter<Question>(getActivity(), android.R.layout.simple_list_item_1, questions);
        setListAdapter(adapter);
    }

}
